<template>
  <div class="app-container">
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="listQuery.Filter" clearable size="small" placeholder="搜索..." style="width: 200px;"
        class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search"
        @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus"
        @click="handleCreate">新增</el-button>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-edit"
        @click="handleUpdate()">修改</el-button>
      <el-button slot="reference" class="filter-item" type="danger" icon="el-icon-delete" size="mini"
        @click="handleDelete()">删除</el-button>
    </div>
    <el-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" @close="cancel()"
      :title="formTitle">
      <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="提醒" prop="Reminder">
          <el-input v-model="form.Reminder" placeholder="请输入提醒" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="打印标记" prop="franking">
          <el-input v-model="form.franking" placeholder="请输入打印标记" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="打印状态" prop="frankStatus">
          <el-input v-model="form.frankStatus" placeholder="请输入打印状态" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="外部状态" prop="ExternalStatus">
          <el-input v-model="form.ExternalStatus" placeholder="请输入外部状态" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="买家留言" prop="BuyerMessage">
          <el-input v-model="form.BuyerMessage" placeholder="请输入买家留言" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="订单备注" prop="OrderNote">
          <el-input v-model="form.OrderNote" placeholder="请输入订单备注" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="承运商" prop="Carrier">
          <el-input v-model="form.Carrier" placeholder="请输入承运商" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="运单号" prop="TrackingNumber">
          <el-input v-model="form.TrackingNumber" placeholder="请输入运单号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="配送方式" prop="DeliveryMethod">
          <el-input v-model="form.DeliveryMethod" placeholder="请输入配送方式" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="买家" prop="Buyer">
          <el-input v-model="form.Buyer" placeholder="请输入买家" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="收货人" prop="Consignee">
          <el-input v-model="form.Consignee" placeholder="请输入收货人" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="详细地址" prop="DetailedAddress">
          <el-input v-model="form.DetailedAddress" placeholder="请输入详细地址" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="Phone">
          <el-input v-model="form.Phone" placeholder="请输入手机" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="实付" prop="Pay">
          <el-input v-model="form.Pay" placeholder="请输入实付" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="优惠" prop="Discount">
          <el-input v-model="form.Discount" placeholder="请输入优惠" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="运费" prop="Freight">
          <el-input v-model="form.Freight" placeholder="请输入运费" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="重量" prop="Weight">
          <el-input v-model="form.Weight" placeholder="请输入重量" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="估重" prop="WeightEstimation">
          <el-input v-model="form.WeightEstimation" placeholder="请输入估重" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="商品总数" prop="TotalGoods">
          <el-input v-model="form.TotalGoods" placeholder="请输入商品总数" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="下单时间" prop="OrderTime">
          <el-input v-model="form.OrderTime" placeholder="请输入下单时间" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="OrderNumber">
          <el-input v-model="form.OrderNumber" placeholder="请输入订单号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="外部订单号" prop="ExternalOrderNumber">
          <el-input v-model="form.ExternalOrderNumber" placeholder="请输入外部订单号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="线上订单号" prop="OnlineOrderNumber">
          <el-input v-model="form.OnlineOrderNumber" placeholder="请输入线上订单号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="平台店铺" prop="PlatformStore">
          <el-input v-model="form.PlatformStore" placeholder="请输入平台店铺" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="付款时间" prop="PaymentTime">
          <el-input v-model="form.PaymentTime" placeholder="付款时间" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="仓库接单时间" prop="WarehouseOrderTime">
          <el-input v-model="form.WarehouseOrderTime" placeholder="请输入仓库接单时间" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="打印批次号" prop="PrintBatchNumber">
          <el-input v-model="form.PrintBatchNumber" placeholder="请输入打印批次号" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="炼选区域" prop="PickingArea">
          <el-input v-model="form.PickingArea" placeholder="请输入炼选区域" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="出库类型" prop="OutboundType">
          <el-input v-model="form.OutboundType" placeholder="请输入出库类型" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="品牌" prop="Brand">
          <el-input v-model="form.Brand" placeholder="请输入品牌" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="到货时间" prop="ArrivalTime">
          <el-input v-model="form.ArrivalTime" placeholder="请输入到货时间" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="体积" prop="Volume">
          <el-input v-model="form.Volume" placeholder="请输入体积" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="商品图片" prop="GoodsImage">
          <el-input v-model="form.GoodsImage" placeholder="请输入商品图片" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="商品名称" prop="GoodsName">
          <el-input v-model="form.GoodsName" placeholder="请输入商品名称" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="规格编码" prop="GoodsSpec">
          <el-input v-model="form.GoodsSpec" placeholder="请输入规格编码" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="标记" prop="Mark">
          <el-input v-model="form.Mark" placeholder="请输入标记" clearable :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="剩余发货时间" prop="RemainingShipmentTime">
          <el-input v-model="form.RemainingShipmentTime" placeholder="请输入剩余发货时间" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button size="small" type="text" @click="cancel">取消</el-button>
        <el-button size="small" v-loading="formLoading" type="primary" @click="save">确认</el-button>
      </div>
    </el-dialog>
    <el-table ref="multipleTable" v-loading="listLoading" :data="list" size="small" style="width: 90%;"
      @sort-change="sortChange" @selection-change="handleSelectionChange" @row-click="handleRowClick">
      <el-table-column type="selection" width="44px"></el-table-column>
      <el-table-column label="提醒" prop="Reminder" align="center" />
      <el-table-column label="打印标记" prop="franking" align="center" />
      <el-table-column label="打印状态" prop="frankStatus" align="center" />
      <el-table-column label="外部状态" prop="ExternalStatus" align="center" />
      <el-table-column label="买家留言" prop="BuyerMessage" align="center" />
      <el-table-column label="订单备注" prop="OrderNote" align="center" />
      <el-table-column label="承运商" prop="Carrier" align="center" />
      <el-table-column label="运单号" prop="TrackingNumber" align="center" />
      <el-table-column label="配送方式" prop="DeliveryMethod" align="center" />
      <el-table-column label="买家" prop="Buyer" align="center" />
      <el-table-column label="收货人" prop="Consignee" align="center" />
      <el-table-column label="详细地址" prop="DetailedAddress" align="center" />
      <el-table-column label="手机" prop="Phone" align="center" />
      <el-table-column label="实付" prop="Pay" align="center" />
      <el-table-column label="优惠" prop="Discount" align="center" />
      <el-table-column label="运费" prop="Freight" align="center" />
      <el-table-column label="重量" prop="Weight" align="center" />
      <el-table-column label="估重" prop="WeightEstimation" align="center" />
      <el-table-column label="商品总数" prop="TotalGoods" align="center" />
      <el-table-column label="下单时间" prop="OrderTime" align="center" />
      <el-table-column label="订单号" prop="OrderNumber" align="center" />
      <el-table-column label="外部订单号" prop="ExternalOrderNumber" align="center" />
      <el-table-column label="线上订单号" prop="OnlineOrderNumber" align="center" />
      <el-table-column label="平台店铺" prop="PlatformStore" align="center" />
      <el-table-column label="付款时间" prop="PaymentTime" align="center" />
      <el-table-column label="仓库接单时间" prop="WarehouseOrderTime" align="center" />
      <el-table-column label="打印批次号" prop="PrintBatchNumber" align="center" />
      <el-table-column label="炼选区域" prop="PickingArea" align="center" />
      <el-table-column label="出库类型" prop="OutboundType" align="center" />
      <el-table-column label="品牌" prop="Brand" align="center" />
      <el-table-column label="到货时间" prop="ArrivalTime" align="center" />
      <el-table-column label="体积" prop="Volume" align="center" />
      <el-table-column label="商品图片" prop="GoodsImage" align="center" />
      <el-table-column label="商品名称" prop="GoodsName" align="center" />
      <el-table-column label="规格编码" prop="GoodsSpec" align="center" />
      <el-table-column label="标记" prop="Mark" align="center" />
      <el-table-column label="剩余发货时间" prop="RemainingShipmentTime" align="center" />
      <el-table-column label="操作" align="center">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)" icon="el-icon-edit" />
          <el-button type="danger" size="mini" @click="handleDelete(row)" icon="el-icon-delete" />
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="totalCount>0" :total="totalCount" :page.sync="page"
      :limit.sync="listQuery.MaxResultCount" @pagination="getList" />
  </div>
</template>
<script>
import Pagination from "@/components/Pagination";
import permission from "@/directive/permission/index.js";
const defaultForm = {
  id: null,
  Reminder: null,
  franking: null,
  frankStatus: null,
  ExternalStatus: null,
  BuyerMessage: null,
  OrderNote: null,
  Carrier: null,
  TrackingNumber: null,
  DeliveryMethod: null,
  Buyer: null,
  Consignee: null,
  DetailedAddress: null,
  Phone: null,
  Pay: null,
  Discount: null,
  Freight: null,
  Weight: null,
  WeightEstimation: null,
  TotalGoods: null,
  OrderTime: null,
  OrderNumber: null,
  ExternalOrderNumber: null,
  OnlineOrderNumber: null,
  PlatformStore: null,
  PaymentTime: null,
  WarehouseOrderTime: null,
  PrintBatchNumber: null,
  PickingArea: null,
  OutboundType: null,
  Brand: null,
  ArrivalTime: null,
  Volume: null,
  GoodsImage: null,
  GoodsName: null,
  GoodsSpec: null,
  Mark: null,
  RemainingShipmentTime: null,
}
export default {
  name: 'ZeroPickOrder',
  components: {
    Pagination
  },
  directives: {
    permission
  },
  props: [],
  data() {
    return {
      rules: {
        Reminder: [{
          required: true,
          message: '请输入提醒',
          trigger: 'blur'
        }],
        franking: [{
          required: true,
          message: '请输入打印标记',
          trigger: 'blur'
        }],
        frankStatus: [{
          required: true,
          message: '请输入打印状态',
          trigger: 'blur'
        }],
        ExternalStatus: [{
          required: true,
          message: '请输入外部状态',
          trigger: 'blur'
        }],
        BuyerMessage: [{
          required: true,
          message: '请输入买家留言',
          trigger: 'blur'
        }],
        OrderNote: [{
          required: true,
          message: '请输入订单备注',
          trigger: 'blur'
        }],
        Carrier: [{
          required: true,
          message: '请输入承运商',
          trigger: 'blur'
        }],
        TrackingNumber: [{
          required: true,
          message: '请输入运单号',
          trigger: 'blur'
        }],
        DeliveryMethod: [{
          required: true,
          message: '请输入配送方式',
          trigger: 'blur'
        }],
        Buyer: [{
          required: true,
          message: '请输入买家',
          trigger: 'blur'
        }],
        Consignee: [{
          required: true,
          message: '请输入收货人',
          trigger: 'blur'
        }],
        DetailedAddress: [{
          required: true,
          message: '请输入详细地址',
          trigger: 'blur'
        }],
        Phone: [{
          required: true,
          message: '请输入手机',
          trigger: 'blur'
        }],
        Pay: [{
          required: true,
          message: '请输入实付',
          trigger: 'blur'
        }],
        Discount: [{
          required: true,
          message: '请输入优惠',
          trigger: 'blur'
        }],
        Freight: [{
          required: true,
          message: '请输入运费',
          trigger: 'blur'
        }],
        Weight: [{
          required: true,
          message: '请输入重量',
          trigger: 'blur'
        }],
        WeightEstimation: [{
          required: true,
          message: '请输入估重',
          trigger: 'blur'
        }],
        TotalGoods: [{
          required: true,
          message: '请输入商品总数',
          trigger: 'blur'
        }],
        OrderTime: [{
          required: true,
          message: '请输入下单时间',
          trigger: 'blur'
        }],
        OrderNumber: [{
          required: true,
          message: '请输入订单号',
          trigger: 'blur'
        }],
        ExternalOrderNumber: [{
          required: true,
          message: '请输入外部订单号',
          trigger: 'blur'
        }],
        OnlineOrderNumber: [{
          required: true,
          message: '请输入线上订单号',
          trigger: 'blur'
        }],
        PlatformStore: [{
          required: true,
          message: '请输入平台店铺',
          trigger: 'blur'
        }],
        PaymentTime: [{
          required: true,
          message: '付款时间',
          trigger: 'blur'
        }],
        WarehouseOrderTime: [{
          required: true,
          message: '请输入仓库接单时间',
          trigger: 'blur'
        }],
        PrintBatchNumber: [{
          required: true,
          message: '请输入打印批次号',
          trigger: 'blur'
        }],
        PickingArea: [{
          required: true,
          message: '请输入炼选区域',
          trigger: 'blur'
        }],
        OutboundType: [{
          required: true,
          message: '请输入出库类型',
          trigger: 'blur'
        }],
        Brand: [{
          required: true,
          message: '请输入品牌',
          trigger: 'blur'
        }],
        ArrivalTime: [{
          required: true,
          message: '请输入到货时间',
          trigger: 'blur'
        }],
        Volume: [{
          required: true,
          message: '请输入体积',
          trigger: 'blur'
        }],
        GoodsImage: [{
          required: true,
          message: '请输入商品图片',
          trigger: 'blur'
        }],
        GoodsName: [{
          required: true,
          message: '请输入商品名称',
          trigger: 'blur'
        }],
        GoodsSpec: [{
          required: true,
          message: '请输入规格编码',
          trigger: 'blur'
        }],
        Mark: [{
          required: true,
          message: '请输入标记',
          trigger: 'blur'
        }],
        RemainingShipmentTime: [{
          required: true,
          message: '请输入剩余发货时间',
          trigger: 'blur'
        }],
      },
      form: Object.assign({}, defaultForm),
      list: null,
      totalCount: 0,
      listLoading: true,
      formLoading: false,
      listQuery: {
        Filter: '',
        Sorting: '',
        SkipCount: 0,
        MaxResultCount: 10
      },
      page: 1,
      dialogFormVisible: false,
      multipleSelection: [],
      formTitle: '',
      isEdit: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getList()
  },
  mounted() {},
  methods: {
    getList() {
      this.listLoading = true;
      this.listQuery.SkipCount = (this.page - 1) * this.listQuery.MaxResultCount;
      this.$axios.gets('', this.listQuery).then(response => {
        this.list = response.items;
        this.totalCount = response.totalCount;
        this.listLoading = false;
      });
    },
    fetchData(id) {
      this.$axios.gets('/' + id).then(response => {
        this.form = response;
      });
    },
    handleFilter() {
      this.page = 1;
      this.getList();
    },
    handleCreate() {
      this.formTitle = '新增零拣打单';
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    handleDelete(row) {
      var params = [];
      let alert = '';
      if (row) {
        params.push(row.id);
        alert = row.name;
      }
      else {
        if (this.multipleSelection.length === 0) {
          this.$message({
            message: '未选择',
            type: 'warning'
          });
          return;
        }
        this.multipleSelection.forEach(element => {
          let id = element.id;
          params.push(id);
        });
        alert = '选中项';
      }
      this.$confirm('是否删除' + alert + '?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.posts('/delete', params).then(response => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          });
          this.getList();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleUpdate(row) {
      this.formTitle = '修改零拣打单';
      this.isEdit = true;
      if (row) {
        this.fetchData(row.id);
        this.dialogFormVisible = true;
      }
      else {
        if (this.multipleSelection.length != 1) {
          this.$message({
            message: '编辑必须选择单行',
            type: 'warning'
          });
          return;
        }
        else {
          this.fetchData(this.multipleSelection[0].id);
          this.dialogFormVisible = true;
        }
      }
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.formLoading = true;
          this.form.roleNames = this.checkedRole;
          if (this.isEdit) {
            this.$axios.posts('/data-post', this.form).then(response => {
              this.formLoading = false;
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 2000
              });
              this.dialogFormVisible = false;
              this.getList();
            }).catch(() => {
              this.formLoading = false;
            });
          }
          else {
            this.$axios.posts('/data-post', this.form).then(response => {
              this.formLoading = false;
              this.$notify({
                title: '成功',
                message: '新增成功',
                type: 'success',
                duration: 2000
              });
              this.dialogFormVisible = false;
              this.getList();
            }).catch(() => {
              this.formLoading = false;
            });
          }
        }
      });
    },
    sortChange(data) {
      const {
        prop,
        order
      } = data;
      if (!prop || !order) {
        this.handleFilter();
        return;
      }
      this.listQuery.Sorting = prop + ' ' + order;
      this.handleFilter();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    cancel() {
      this.form = Object.assign({}, defaultForm);
      this.dialogFormVisible = false;
      this.$refs.form.clearValidate();
    },
  }
}

</script>
<style>
</style>
